﻿using B.S.BasicData.Domain.XU;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfaces;
using B.S.BasicData.Write.Api.Application.Command.Xu;
using MediatR;

namespace B.S.BasicData.Write.Api.Application.CommandHandler.Xu
{  

   /// <summary>
   /// 删除箱子
   /// </summary>
    public class DelBoxHandler : IRequestHandler<DelBoxCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<BoxModel> _boxbaseRepository;

        public DelBoxHandler(IBaseRepository<BoxModel> boxbaseRepository) 
        {
           _boxbaseRepository = boxbaseRepository;
        }
        public Task<ApiResult<int>> Handle(DelBoxCommand request, CancellationToken cancellationToken)
        {
             ApiResult<int> result = new ApiResult<int>();
            var delbox= _boxbaseRepository.GetById(request.Id);
            var del = _boxbaseRepository.Delete(delbox);
            if (del > 0)
            {
                result.Code = ApiEnums.Success;
                result.Msg = "删除成功";
                result.Data = del;
            }
            else
            {
                result.Code = ApiEnums.Fail;
                result.Msg = "删除失败";
                result.Data = del;
            }
            return Task.FromResult(result);
        }
    }
}
